from django.db import models

# Create your models here.
class QuestionType(models.Model):  #定义 问题类型 的数据库表
	question_type = models.CharField(max_length = 50)
	
	def __str__(self):
		return self.question_type
		
class Question(models.Model):          #定义 问题 的数据库表（主键是问题类型）
	question_type = models.ForeignKey(QuestionType,
	on_delete = models.CASCADE)
	question_text = models.CharField(
	max_length = 200,unique = True)
	pub_date = models.DateTimeField(auto_now_add = True)

	def __str__(self):
                return self.question_text
        
class Choice(models.Model):         #定义 选项 的数据库表（主键是问题）
	question = models.ForeignKey(Question,
	on_delete = models.CASCADE)
	choice_text = models.CharField(max_length = 100)

	def __str__(self):
                return self.choice_text
        
class Answer(models.Model):         #定义 答案 的数据库表（主键是问题）
	question = models.ForeignKey(Question,
	on_delete = models.CASCADE)
	answer_text = models.CharField(max_length = 300)

	def __str__(self):
                return self.answer_text


        
